package com.kangyi.app.controller;

import com.kangyi.app.service.GuestService;
import com.kangyi.dto.AddGuestDTO;
import com.kangyi.dto.AddGuestsStayingDTO;
import com.kangyi.dto.CheckinApplyDTO;
import com.kangyi.result.Result;
import com.kangyi.vo.GuestListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/app/guest")
@Slf4j
@Api(tags = "入住人相关接口")
public class GuestController {

    @Autowired
    private GuestService guestService;

    @PostMapping("/checkinApply")
    @ApiOperation("养老院入住申请")
    public Result checkinApply(@RequestBody CheckinApplyDTO checkinApplyDTO){
        log.info("养老院入住申请:{}",checkinApplyDTO);
        try {
            guestService.checkinApply(checkinApplyDTO);
            return Result.success("申请提交成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/add")
    @ApiOperation("新增入住人")
    public Result addGuest(@RequestBody AddGuestDTO addGuestDTO){
        log.info("新增入住人:{}",addGuestDTO);
        try {
            guestService.addGuest(addGuestDTO);
            return Result.success("新增成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @GetMapping("/list/{userId}")
    @ApiOperation("查询账户下的入住人")
    public Result<List<GuestListVO>> list(@PathVariable Integer userId){
        log.info("查询账户下的入住人:{}",userId);
        try {
            List<GuestListVO> guestListVO = guestService.list(userId);
            return Result.success(guestListVO,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
